/*     */ package com.zimbra.qa.unittest.server;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DataSourceBy;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.datasource.CalDavDataImport;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.Folder.FolderOptions;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.soap.admin.type.DataSourceType;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import junit.framework.Assert;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestCalDavImportServer
/*     */   extends TestCase
/*     */ {
/*  39 */   private static final String NAME_PREFIX = TestCalDavImportServer.class.getSimpleName();
/*  40 */   private static final String USER_NAME = NAME_PREFIX + "user1";
/*  41 */   private static final String DATA_SOURCE_NAME = NAME_PREFIX;
/*  42 */   private static final String TEMP_USER_NAME = NAME_PREFIX + "Temp";
/*  43 */   private Folder rootFolder = null;
/*  44 */   private Account account = null;
/*  45 */   private Mailbox mbox = null;
/*     */   
/*     */   public void setUp() throws Exception
/*     */   {
/*  49 */     cleanUp();
/*  50 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  52 */     Account user1Account = prov.createAccount(TestUtil.getAddress(USER_NAME), "test123", null);
/*     */     
/*  54 */     Mailbox user1Mbox = MailboxManager.getInstance().getMailboxByAccount(user1Account);
/*     */     
/*  56 */     this.account = prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
/*  57 */     this.mbox = MailboxManager.getInstance().getMailboxByAccount(this.account);
/*  58 */     this.rootFolder = this.mbox.createFolder(null, USER_NAME, 11, new Folder.FolderOptions().setDefaultView(MailItem.Type.APPOINTMENT));
/*  59 */     createDataSource();
/*     */   }
/*     */   
/*     */   public void testRootFolderSyncToken() throws Exception {
/*  63 */     Assert.assertTrue(this.rootFolder.getLastSyncDate() == 0L);
/*     */     
/*  65 */     CalDavDataImport davDataImport = new CalDavDataImport(getDataSource());
/*  66 */     davDataImport.importData(null, true);
/*     */     
/*  68 */     Assert.assertTrue(this.rootFolder.getLastSyncDate() > 0L);
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/*  73 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void createDataSource() throws Exception {
/*  77 */     Provisioning prov = Provisioning.getInstance();
/*  78 */     int port = Integer.parseInt(TestUtil.getServerAttr("zimbraMailSSLPort"));
/*  79 */     Map<String, Object> attrs = new HashMap();
/*  80 */     attrs.put("zimbraDataSourceEnabled", "TRUE");
/*  81 */     attrs.put("zimbraDataSourceHost", TestUtil.getServerAttr("zimbraServiceHostname"));
/*  82 */     attrs.put("zimbraDataSourcePort", Integer.toString(port));
/*  83 */     attrs.put("zimbraDataSourceUsername", USER_NAME);
/*  84 */     attrs.put("zimbraDataSourcePassword", "test123");
/*  85 */     attrs.put("zimbraDataSourceFolderId", Integer.toString(this.rootFolder.getId()));
/*  86 */     attrs.put("zimbraDataSourceConnectionType", "ssl");
/*  87 */     attrs.put("zimbraDataSourceAttribute", "p:/principals/users/_USERNAME_");
/*  88 */     prov.createDataSource(this.account, DataSourceType.caldav, DATA_SOURCE_NAME, attrs);
/*     */   }
/*     */   
/*     */   private DataSource getDataSource() throws Exception {
/*  92 */     Provisioning prov = Provisioning.getInstance();
/*  93 */     return prov.get(this.account, Key.DataSourceBy.name, DATA_SOURCE_NAME);
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception
/*     */   {
/*  98 */     Account account = TestUtil.getAccount(TEMP_USER_NAME);
/*  99 */     if (account != null) {
/* 100 */       Provisioning prov = Provisioning.getInstance();
/* 101 */       DataSource ds = prov.get(account, Key.DataSourceBy.name, DATA_SOURCE_NAME);
/* 102 */       if (ds != null) {
/* 103 */         prov.deleteDataSource(account, ds.getId());
/*     */       }
/* 105 */       TestUtil.deleteTestData(TEMP_USER_NAME, NAME_PREFIX);
/* 106 */       TestUtil.deleteAccount(TEMP_USER_NAME);
/*     */     }
/* 108 */     account = TestUtil.getAccount(USER_NAME);
/* 109 */     if (account != null) {
/* 110 */       TestUtil.deleteTestData(USER_NAME, NAME_PREFIX);
/* 111 */       TestUtil.deleteAccount(USER_NAME);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/server/TestCalDavImportServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */